package com.jimmy.tx.service.impl;

import com.jimmy.tx.dao.LogDao;
import com.jimmy.tx.dao.UserDao;
import com.jimmy.tx.service.LogService;
import com.jimmy.tx.service.RoleService;
import org.springframework.transaction.annotation.Transactional;

/**
 * @version 1.0
 * @ ClassName RoleServiceImpl
 * <p> TODO
 * @ author JIMMY
 * @ Date 2020/11/8 0008 上午 9:16
 */
public class RoleServiceImpl implements RoleService {
    private UserDao userDao;
    private LogDao logDao;
    private LogService logService;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public void setLogDao(LogDao logDao) {
        this.logDao = logDao;
    }

    public void setLogService(LogService logService) {
        this.logService = logService;
    }

    /**
     * 用声明式事务替换了编程式事务
     * @param from
     * @param to
     * @param money
     * 事务嵌套可参考 https://blog.csdn.net/qq_35830949/article/details/79581198
     */
//    @Transactional
    public void transfer(String from, String to, Double money) {
        userDao.outMoney(from,money);
        userDao.inMoney(to,money);
        //int i = 1/0;    //（加在这没效果很是奇怪）
        //事务管理者有事务但协调者不需要事务就会报错
        //userDao.fn();    // Existing transaction found for transaction marked with propagation 'never'
        //管理者有事务但是日志还想要保存配置事务协调者的传播行为让他还可以保存
//        logDao.insertLog(1,"insert log");

        logService.insertLog(1,"insert log");

        //int i = 1/0;    //（报后报异常日志才能保存）
    }



}
